package leetcode.每日一题;

import org.junit.Test;

import java.util.*;

/**
 * @author ：zsy
 * @date ：Created 2021/11/24 12:05
 * @description：https://leetcode-cn.com/problems/reconstruct-original-digits-from-english/
 */
public class 从英文中重建数字 {
    @Test
    public void test() {
        Solution solution = new Solution();
        System.out.println(solution.originalDigits("fviefuro"));
    }

    class Solution {
        /**
         * zero one two three four five six seven eight nine
         * zero six nine five two four seven one three eight
         * @param s
         * @return
         */
        public String originalDigits(String s) {
            Map<Character, Integer> map = new HashMap<>();
            for (int i = 0; i < s.length(); i++) {
                char ch = s.charAt(i);
                map.put(ch, map.getOrDefault(ch, 0) + 1);
            }
            int cnt[] = new int[10];
            cnt[0] = map.getOrDefault('z', 0);
            cnt[2] = map.getOrDefault('w', 0);
            cnt[4] = map.getOrDefault('u', 0);
            cnt[5] = map.getOrDefault('f', 0) - cnt[4];
            cnt[7] = map.getOrDefault('v', 0) - cnt[5];
            cnt[1] = map.getOrDefault('o', 0) - cnt[0] - cnt[2] - cnt[4];
            cnt[6] = map.getOrDefault('x', 0);
            cnt[8] = map.getOrDefault('g', 0);
            cnt[3] = map.getOrDefault('h', 0) - cnt[8];
            cnt[9] = map.getOrDefault('i', 0) - cnt[5] - cnt[6] - cnt[8];
            StringBuilder builder = new StringBuilder();
            for (int i = 0; i < cnt.length; i++) {
                for (int j = 0; j < cnt[i]; j++) {
                    builder.append(i);
                }
            }
            return builder.toString();
        }
    }
}
